#define _CRT_SECURE_NO_WARNINGS 1

#include "game.h"
void Pr(char a[ROWS][COLS], int m, int n, char ch)
{
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < COLS; j++)
		{
			a[i][j] = ch;
		}
	}
}


void start(char a[ROWS][COLS], char ch)
{
	for (int i = 0; i <= ROW; i++)
	{
		printf("%2d", i);
	}
	printf("\n");
	for (int i = 1; i <= ROW; i++)
	{
		printf("%2d ", i);
		for (int j = 1; j <= COL; j++)
		{
			if (a[i][j] == 0) {
				printf("%c ", '0');
			}
			else {
				printf("%c ", a[i][j]);
			}
		}
		printf("\n");
	}
}

int An(int a, int b, char show[][COLS])
{
	if (a > 0 && a <= ROW && b > 0 && b <= COL && (show[a][b] == '*'||show[a][b] == '$'))
	{
		return 5;
	}
	else
		return 0;
}

char Kn(int a, int b, char answer[ROWS][COLS])
{
	return answer[a][b - 1] + answer[a][b + 1] + answer[a + 1][b] + answer[a - 1][b] + answer[a - 1][b - 1] + answer[a + 1][b - 1] + answer[a + 1][b + 1] + answer[a - 1][b + 1] - 7 * '0';
}

void Pn(int a, int b, char show[ROWS][COLS], char answer[ROWS][COLS], int* count)
{
	int c = An(a, b, show);
	if (c > 0 && show[a][b] != 0 && show[a][b] != '$')
	{
		show[a][b] = Kn(a, b, answer);
		(*count)++;
		if (show[a][b] == '0')
		{
			show[a][b] = 0;
			Pn(a + 1, b, show, answer, count);
			Pn(a, b + 1, show, answer, count);
			Pn(a - 1, b, show, answer, count);
			Pn(a, b - 1, show, answer, count);
			Pn(a + 1, b + 1, show, answer, count);
			Pn(a - 1, b + 1, show, answer, count);
			Pn(a - 1, b - 1, show, answer, count);
			Pn(a + 1, b - 1, show, answer, count);
		}
	}
}

void Xn(char answer[ROWS][COLS], int c, int d)
{
	srand((unsigned int)time(NULL));
	int x, y;
	int ko = ln;
	while (ko > 0)
	{
		x = rand() % ROW + 1;
		y = rand() % COL + 1;
		if (answer[x][y] == '0')
		{
			if (x != c && y != d) {
				answer[x][y] = '1';
				ko--;
			}
		}
	}
}


void mm(char show[][COLS],int m,int n)
{
	show[m][n] = '$';
}


int Q(char show[][COLS], char answer[][COLS], int m, int n)
{
	if (show[m][n] == '*')
	{
		return 1;
	}
	else
		return 0;
}